﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Common.Utils;

public partial class sysadmin_VirtualManager_AddVirtual :PowerCreator.LMS.Web.Base.BasePage
{
    VirtualDirectory opVitrual = new VirtualDirectory();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
        }
    }

    protected override void InitPage()
    {
        rfv_VirIISName.ErrorMessage = GetLanageValueByKey("lbl_addvirtual_nametishi", PowerCreator.LMS.Language.LanagetItemType.Page);
        rfv_txt_VirPath.ErrorMessage = GetLanageValueByKey("lbl_addvirtual_lujingtishi", PowerCreator.LMS.Language.LanagetItemType.Page);
        rfv_txt_VirIp.ErrorMessage = GetLanageValueByKey("lbl_addvirtual_iptishi", PowerCreator.LMS.Language.LanagetItemType.Page);
        rfv_txt_VirMmsName.ErrorMessage = GetLanageValueByKey("lbl_addvirtual_liumeititishi", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_InfoTitle.Text = GetLanageValueByKey("lbl_AddVirtual_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_Information.Text = GetLanageValueByKey("lbl_AddVirtual_Information", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirIisName.Text = GetLanageValueByKey("lbl_AddVirtual_VirIisName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirPath.Text = GetLanageValueByKey("lbl_AddVirtual_VirPath", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirIp.Text = GetLanageValueByKey("lbl_AddVirtual_VirIp", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_WMServices.Text = GetLanageValueByKey("lbl_AddVirtual_WMServices", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirMmsName.Text = GetLanageValueByKey("lbl_AddVirtual_VirMmsName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_FTP.Text = GetLanageValueByKey("lbl_AddVirtual_FTP", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirFtpName.Text = GetLanageValueByKey("lbl_AddVirtual_VirFtpName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirFtpPassword.Text = GetLanageValueByKey("lbl_AddVirtual_VirFtpPassword", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddVirtual_VirFtpPort.Text = GetLanageValueByKey("lbl_AddVirtual_VirFtpPort", PowerCreator.LMS.Language.LanagetItemType.Page);

        lbl_Description_title.Text = GetLanageValueByKey("lbl_AddVirtual_Description_title", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_1.Text = GetLanageValueByKey("lbl_AddVirtual_Description_1", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_2.Text = GetLanageValueByKey("lbl_AddVirtual_Description_2", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_3.Text = GetLanageValueByKey("lbl_AddVirtual_Description_3", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_4.Text = GetLanageValueByKey("lbl_AddVirtual_Description_4", PowerCreator.LMS.Language.LanagetItemType.Page);

        btn_Save.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Reset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }

    private bool CheckPageData()
    {
        string search = string.Format("VirIisName='{0}'", txt_VirIisName.Text);
        if (opVitrual.QueryVirtualCount(search) != 0)
        {
            lbl_AddVirtual_msg_viriisname.Text = GetLanageValueByKey("lbl_AddVirtual_msg_viriisname", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        //if (!IPUtils.IsIP(txt_VirIp.Text))
        //{
        //    lbl_AddVirtual_msg_ip.Text = GetLanageValueByKey("lbl_AddVirtual_msg_ip", PowerCreator.LMS.Language.LanagetItemType.MSG);
        //    return false;
        //}
        if (!string.IsNullOrEmpty(txt_VirFtpPort.Text))
        {
            if (!IntUtils.IsNumber(txt_VirFtpPort.Text))
            {
                lbl_AddVirtual_msg_virftpport.Text = GetLanageValueByKey("lbl_AddVirtual_msg_virftpport", PowerCreator.LMS.Language.LanagetItemType.MSG);
                return false;
            }
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;

        VOTVirtualDirectory vo = new VOTVirtualDirectory();
        vo.VirFtpName = txt_VirFtpName.Text;
        vo.VirFtpPassword = txt_VirFtpPassword.Text;
        if (!string.IsNullOrEmpty(txt_VirFtpPort.Text))
        {
            vo.VirFtpPort = int.Parse(txt_VirFtpPort.Text);
        }
        vo.VirIisName = txt_VirIisName.Text;
        vo.VirIp = txt_VirIp.Text;
        vo.VirMmsName = txt_VirMmsName.Text;
        vo.VirPath = txt_VirPath.Text;

        if (opVitrual.AddVirtual(vo))
        {
            string url = "VirtualManager.aspx";
            Script.RedirectURL(url);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "VirtualManager.aspx";
        Script.RedirectURL(url);
    }
}
